<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * 首页轮播图管理
 * @filename admin_flash.php
 * @author hmw
 *
 */
class Admin_flash extends MY_Controller {

	function Admin_flash()
	{
		parent::MY_Controller();
		parent::check_admin_login();
	}

	function index()
	{
		self::flash_list();
	}
	
	function flash_list(){
		$this->load->model('mflash');
		$flashs = $this->mflash->get_flash_list();
		$this->template->view('admin/flash_list',array('flashs'=>$flashs));
	}
	
	function flash_new(){
		$this->template->view('admin/flash_add');
	}
	
	function flash_add(){
		$config['upload_path'] = $this->config->item('flash_uri').'img/';
		$config['allowed_types'] = $this->config->item('flash_img_types');
		$config['max_size'] = $this->config->item('flash_img_max_size');
		$config['max_width'] = $this->config->item('flash_img_width');
		$config['max_height'] = $this->config->item('flash_img_height');
		$this->load->library('upload', $config);
		if (!$this->upload->do_upload('img')) {
			echo '文件上传失败，可能原因为：<br />'.$this->uplaod->display_errors();
		} else {
			$title = $this->input->post('title') ? $this->input->post('title') : '谋成网络首页轮播图';
			$link  = $this->input->post('link') ? $this->input->post('link') : base_url();
			$state = $this->input->post('state');
			$forder = $this->input->post('forder') ? $this->input->post('forder') : 1;
			$up_time = date('Y-m-d H:i:s');
			$data = $this->upload->data();
			$img = $data['file_name'];
			$values = array('title'=>$title,'link'=>$link,'state'=>$state,'img'=>$img,'forder'=>$forder,'up_time'=>$up_time);
			$this->load->model('mflash');
			if ($this->mflash->insert_new_flash($values)) {
				echo '轮播图添加成功！';
			} else {
				echo '轮播图添加失败！';
			}
		}
	}
	
	function flash_disable($id=''){
		if ($id === '') {
			echo '必须选择项目方可继续操作！';return;
		}
		$this->load->model('mflash');
		if ($this->mflash->update_flash_state($id,'0')) {
			echo '所选FLASH成功停用！';
		} else {
			echo '停用失败！';
		}
	}
	
	function flash_enable($id=''){
		if ($id === '') {
			echo '必须选择项目方可继续操作！';return;
		}
		$this->load->model('mflash');
		if ($this->mflash->update_flash_state($id,'1')) {
			echo '所选FLASH成功启用！';
		} else {
			echo '启用失败！';
		}
	}
	
	function flash_del($id){
		if ($id === '') {
			echo '必须选择项目方可继续操作！';return;
		}
		$this->load->model('mflash');
		if ($this->mflash->delete_flash($id)) {
			echo '删除成功！';
		} else {
			echo '删除失败！';
		}
	}
	
	/**
	 * 编辑首页轮播图
	 * @param $id
	 * @return null
	 */
	function flash_edit($id){
		if ($id === '') {
			echo '必须选择项目方可继续操作！';return;
		}
		$this->load->model('mflash');
		$info = $this->mflash->get_flash_info($id);
		//print_r($info);exit;
		$this->template->view('admin/flash_edit',array('info'=>$info));
	}
	
	/**
	 * 修改轮播图信息
	 * @return null
	 */
	function flash_modify(){
		$id = $this->input->post('id');
		$title = $this->input->post('title') ? $this->input->post('title') : '谋成网络首页轮播图';
		$link  = $this->input->post('link') ? $this->input->post('link') : base_url();
		$state = $this->input->post('state');
		$forder = $this->input->post('forder') ? $this->input->post('forder') : 1;
		$up_time = date('Y-m-d H:i:s');
		$values = array('title'=>$title,'link'=>$link,'state'=>$state,'forder'=>$forder,'up_time'=>$up_time);
		
		$config['upload_path'] = $this->config->item('flash_uri').'img/';
		$config['allowed_types'] = $this->config->item('flash_img_types');
		$config['max_size'] = $this->config->item('flash_img_max_size');
		$config['max_width'] = $this->config->item('flash_img_width');
		$config['max_height'] = $this->config->item('flash_img_height');
		$this->load->library('upload', $config);
		if (!$this->upload->do_upload('img')) {
			//echo '文件上传失败，可能原因为：<br />'.$this->uplaod->display_errors();
		} else {
			$data = $this->upload->data();
			$img = $data['file_name'];
			$values['img'] = $img;
		}
		$this->load->model('mflash');
		if ($this->mflash->update_flash_info($id,$values)) {
			echo '轮播图修改成功！';
		} else {
			echo '轮播图修改失败！';
		}
	}
	

}

/* End of file admin_flash.php */
/* Location: ./system/application/controllers/admin_flash.php */
?>